﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class gbook : System.Web.UI.Page
{
    [RequestQuery.Query(QueryKey = "keyword")]
    public string keyword = string.Empty;  //留言者名称
    
    protected void Page_Load(object sender, EventArgs e)
    {
        RequestQuery.SetQueryValues();

        if (!IsPostBack)
        {
            txt_msgkeyword.Text = keyword;

            ProSplitPage1.DataSource = GetPagingData();  //给分页控件附值
            ProSplitPage1.AppendQuery = RequestQuery.GetQueryValues();
            repeater1.DataSource = ProSplitPage1.SplitSource(); //返回拆分结果
            repeater1.DataBind();
            
        }
    }

    #region 分页方法

    public DataSet GetPagingData()
    {
        StringBuilder sql = new StringBuilder();
        sql.Append(
@"SELECT * FROM [tab_Message] where 1 = 1");
        /* 追加条件*/
        if (keyword != string.Empty)
        {
            sql.Append(" and msg_Title like '%").Append(keyword).Append("%'");
        }

        string Primary = "msg_ID"; //主键
        string Orderby = Primary + " DESC";  //排序
        return DataEntity.Common.ExecuteSplitPage(sql.ToString(), Primary, Orderby, ProSplitPage1.MaxRows, ProSplitPage1.PageIndex);
    }
    #endregion

    protected void btn_ok_Click(object sender, ImageClickEventArgs e)
    {
        DataEntity.tab_Message t = new DataEntity.tab_Message();
        t.msg_IsNewMsg = true;
        t.msg_Title = Convert.ToString(txt_Title.Text);
        t.msg_Relation = Convert.ToString(txt_Relation.Text);
        t.msg_Email = Convert.ToString(txt_Email.Text);
        t.msg_Content = Convert.ToString(txt_Content.Text);
        t.Insert();
        
        UIMethod.Alert("留言成功，请等待回复..");
        UIMethod.GoToURL(Request.Path, false);
    }
}
